package com.dudu.controller;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.dudu.bean.UserBean;
import com.dudu.service.ISmsInfoDetailService;
import com.dudu.service.impl.SmsInfoDetailServiceImpl;

import core.CoreService;

/**
 * 短信发送结果查询
 * 
 * @author gaoxs
 * 
 */
public class SmsInfoDetailController extends CoreService implements ISmsInfoDetailController {
    // 当前登陆用户
    private final String KEY_CURRENT_USER = "key_current_user";
    private ISmsInfoDetailService smsServcie = new SmsInfoDetailServiceImpl();

    /**
     * 查询白名单，按分页条件查询
     * 
     * @return
     */
    public String queryAll() {
	log.info("SmsInfoDetailController.queryAll");
	JSONObject object = new JSONObject();
	JSONArray jsonArray = new JSONArray();
	// 获取当前登录用户信息
	UserBean currentUser = (UserBean) this.getSession().getAttribute(KEY_CURRENT_USER);
	if (currentUser != null) {
	    // 获取页面分页用信息
	    String pageSql = this.getPageSql();
	    // 获取查询参数信息
	    String paramSql = this.convertParams();
	    // 总数量
	    int totalAcount = this.smsServcie.getTotalAcount(paramSql);
	    List<JSONObject> list = this.smsServcie.queryAll(paramSql, pageSql);
	    jsonArray = JSONArray.fromObject(list);

	    JSONObject dataobject = new JSONObject();
	    object.put("flag", "000000");
	    object.put("desc", "success");
	    dataobject.put("totalItemNum", totalAcount);
	    dataobject.put("items", jsonArray);
	    object.put("data", dataobject);
	} else {
	    object.put("flag", "100000");
	}
	return returnData(object.toString());
    }

    /**
     * 上行短信查询
     * 
     * @return
     */
    public String queryAllUpstreamList() {
	log.info("SmsInfoDetailController.queryAllUpstreamList");
	JSONObject object = new JSONObject();
	JSONArray jsonArray = new JSONArray();
	// 获取当前登录用户信息
	UserBean currentUser = (UserBean) this.getSession().getAttribute(KEY_CURRENT_USER);
	if (currentUser != null) {
	    // 获取页面分页用信息
	    String pageSql = this.getPageSql();
	    // 获取查询参数信息
	    String paramSql = this.convertParams();
	    // 总数量
	    int totalAcount = this.smsServcie.getTotalUpstream(paramSql);
	    List<JSONObject> list = this.smsServcie.queryAllUpstreamList(paramSql, pageSql);
	    jsonArray = JSONArray.fromObject(list);

	    JSONObject dataobject = new JSONObject();
	    object.put("flag", "000000");
	    object.put("desc", "success");
	    dataobject.put("totalItemNum", totalAcount);
	    dataobject.put("items", jsonArray);
	    object.put("data", dataobject);
	} else {
	    object.put("flag", "100000");
	}
	return returnData(object.toString());
    }
}
